﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using CardLogistics.Web.Components;
using System.Data;

namespace CardLogistics.Web
{
    public partial class Left : BasePage
    {
        protected string MenuStr = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MenuStr = GetUserMenu();
            }
        }

        #region 获取用户权限菜单
        /// <summary>
        /// 根据用户登录信息获取用户的权限菜单
        /// </summary>
        /// <returns></returns>
        private string GetUserMenu()
        {
            StringBuilder sbStr = new StringBuilder();
            DataTable dt = CardLogistics.DAL.DbHelperSQL.GetQueryResult("select * from sys_menus where MENUNAME not like '%预警%' and menuid in(select menuid from sys_sysrolemenus where Status=1 and RoleId='" + LoggedUser.ROLEID + "') ");
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow[] drParent = dt.Select(" PARENTID=0 ", "sort");
                if (drParent.Length > 0)
                {
                    for (int i = 0; i < drParent.Length; i++)
                    {
                        sbStr.Append("<dd>");
                        sbStr.Append("<div class='title'>");
                        sbStr.Append("<span><img src='images/leftico01.png' /></span>" + drParent[i]["MENUNAME"].ToString() + "");
                        sbStr.Append("</div>");
                        sbStr.Append("<ul class='menuson'>");
                        DataRow[] drMenus = dt.Select(" PARENTID=" + drParent[i]["menuid"] + "", "sort");
                        for (int m = 0; m < drMenus.Length; m++)
                        {
                            sbStr.Append("<li><cite></cite>");
                            if (drMenus[m]["opentype"].ToString() == "1")
                            {
                                sbStr.Append("<a href='" + drMenus[m]["URLWINFORMNAME"].ToString() + "?mid=" + drMenus[m]["menuid"].ToString() + "' target='_blank'>" + drMenus[m]["MENUNAME"].ToString() + "</a>");
                            }
                            else
                            {
                                sbStr.Append("<a href='" + drMenus[m]["URLWINFORMNAME"].ToString() + "?mid=" + drMenus[m]["menuid"].ToString() + "' target='rightFrame'>" + drMenus[m]["MENUNAME"].ToString() + "</a>");
                            }
                            sbStr.Append("<i></i></li>");
                        }

                        sbStr.Append("</ul>");
                        sbStr.Append("</dd>");
                    }
                }
            }
            return sbStr.ToString();
        }
        #endregion
    }
}